package com.haiyan.role.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.haiyan.base.BaseController;
import com.haiyan.role.bean.RoleBean;
import com.haiyan.role.service.RoleService;
import com.haiyan.role.service.impl.RoleServiceImpl;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * 这里要做的事情：先判断请求到的方法是什么
 *              调用servicr的方法(拿到前端的值，塞进service的方法中，返回响应)
 */

@WebServlet(name="zhyRoleGetController",urlPatterns="/zhyRole/get.do")
public class RoleGetController extends BaseController {

    private RoleService roleService = new RoleServiceImpl();
    
    @Override
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        // 请求拿到URl的method后的值
        String method = request.getParameter("method");
        /*List<RoleBean> RoleList =new ArrayList<RoleBean>();*/
        // 拿到method=什么就做什么事情
        if("findRole".equals(method)){
            findRole(request,response);
        }
    }


    public void findRole(ServletRequest request, ServletResponse response){
        String id = request.getParameter("id");
        int i = Integer.parseInt(id);

        RoleBean role = roleService.findRoleNameById(i);

        boolean check=role != null;
        printData(check,role,500,response);

    }

}
